Outdated CHICKEN release

This is a manual page for an old and unsupported version of CHICKEN. If you are still using it, please consider migrating to the latest version. You can find the manual for the latest release here.

  1. Outdated CHICKEN release
  2. Unit utils
    1. Environment Query
      1. apropos
      2. apropos-list
    2. Iterating over input lines and files
      1. for-each-line
      2. for-each-argv-line
    3. Executing shell commands with formatstring and error checking
      1. system*
    4. Reading a file's contents
      1. read-all

Unit utils

This unit contains apropos and functions as a "grab bag" of procedures without a good home, and which don't have to be available by default (as compared to the extras unit).

This unit uses the extras and regex units.

Environment Query

apropos

[procedure] (apropos SYMBOL-PATTERN [ENVIRONMENT] [#:MACROS?])

Displays symbols & type matching SYMBOL-PATTERN in the ENVIRONMENT on the (current-output-port).

SYMBOL-PATTERN
A symbol, string, or regex. When symbol or string substring matching is performed.
ENVIRONMENT
An environment. When missing the (interaction-environment) is assumed.
#:MACROS?
Keyword argument. A boolean. Include macro symbols? When missing #f is assumed.

apropos-list

[procedure] (apropos-list SYMBOL-PATTERN [ENVIRONMENT] [#:MACROS?])

Like apropos but returns a list of matching symbols.

Iterating over input lines and files

for-each-line

[procedure] (for-each-line PROCEDURE [PORT])

Calls PROCEDURE for each line read from PORT (which defaults to the value of (current-input-port). The argument passed to PROCEDURE is a string with the contents of the line, excluding any line-terminators. When all input has been read from the port, for-each-line returns some unspecified value.

for-each-argv-line

[procedure] (for-each-argv-line PROCEDURE)

Opens each file listed on the command line in order, passing one line at a time into PROCEDURE. The filename - is interpreted as (current-input-port). If no arguments are given on the command line it again uses the value of (current-input-port). During execution of PROCEDURE, the current input port will be correctly bound to the current input source.

This code will act as a simple Unix cat(1) command:

(for-each-argv-line print)

Executing shell commands with formatstring and error checking

system*

[procedure] (system* FORMATSTRING ARGUMENT1 ...)

Similar to (system (sprintf FORMATSTRING ARGUMENT1 ...)), but signals an error if the invoked program should return a nonzero exit status.

Reading a file's contents

read-all

[procedure] (read-all [FILE-OR-PORT])

If FILE-OR-PORT is a string, then this procedure returns the contents of the file as a string. If FILE-OR-PORT is a port, all remaining input is read and returned as a string. The port is not closed. If no argument is provided, input will be read from the port that is the current value of (current-input-port).

Previous: Unit posix

Next: Unit tcp